#include "pathaddparamdlg.h"
#include <QMessageBox>
#include "cfgjsonrw.h"

PathAddParamDlg::PathAddParamDlg(QWidget* parent)
	: QDialog(parent)
{
	ui.setupUi(this);
}

PathAddParamDlg::~PathAddParamDlg()
{}

void PathAddParamDlg::CreateNewPath()
{
	on_pushButton_clicked();
	ui.lineEdit->setText("");
	ui.comboBox->setCurrentIndex(0);
	ui.comboBox_2->setCurrentIndex(0);
	this->exec();
}
PathCfg PathAddParamDlg::GetPath()
{
	PathCfg cfg = {};
	cfg.id = 1;
	cfg.name = ui.lineEdit->text();
	PathPointCfg cfg1 = {};
	cfg1.name = ui.comboBox->currentText();
	cfg1.acc = 30;
	cfg1.pointType = 2;
	cfg1.pointId = cfg.id() * 10;
	cfg1.vel = 40;
	cfg1.zone = 10;

	PathPointCfg cfg2 = {};
	cfg2.name = ui.comboBox_2->currentText();
	cfg2.acc = 30;
	cfg2.pointType = 2;
	cfg2.pointId = cfg.id() * 10 + 1;
	cfg2.vel = 40;
	cfg2.zone = 10;
	cfg.points().append(cfg1);
	cfg.points().append(cfg2);
	return cfg;
}


// 更新点位
void PathAddParamDlg::on_pushButton_clicked()
{
	ui.comboBox->clear();
	ui.comboBox_2->clear();
	ui.comboBox->addItem("原点");
	ui.comboBox_2->addItem("原点");
	ui.comboBox->addItem("固定点");
	ui.comboBox_2->addItem("固定点");

	auto line = cfgrw->GetAllBoxlineID();
	ui.comboBox->addItems(line);
	ui.comboBox_2->addItems(line);
	auto plate = cfgrw->GetAllStackPlateID();
	ui.comboBox->addItems(plate);
	ui.comboBox_2->addItems(plate);
	auto unplate = cfgrw->GetAllUnstackPlateID();
	ui.comboBox->addItems(unplate);
	ui.comboBox_2->addItems(unplate);
	auto stack = cfgrw->GetPlateStackCfg();
	ui.comboBox->addItem(stack.id());
	ui.comboBox_2->addItem(stack.id());
}
// 完成
void PathAddParamDlg::on_pushButton_2_clicked()
{
	this->done(0);
}
